﻿using System;
using Iesi.Collections.Generic;
using Ornament;
using Ornament.Domain;

namespace JinTai.WebSite
{
    public class FashiSchedule : DomainObject<Guid>
    {
        private ISet<FashiScheduleItem> _items;

        public FashiSchedule()
        {
            CreateTime = DateTime.Now;
        }

        public virtual string Subject { get; set; }

        public virtual ISet<FashiScheduleItem> Items
        {
            get
            {
                if (_items == null)
                    Items = new OrderedSet<FashiScheduleItem>();
                return _items;
            }
            private set { _items = value; }
        }

        public virtual Boolean Show { get; set; }
        public virtual DateTime CreateTime { get; private set; }

        protected override int CreateHashCode()
        {
            return Subject.GetHashCode();
        }
    }

    public class FashiScheduleItem
    {
        private DateTime startDate;

        public virtual DateTime StartDate
        {
            get { return startDate; }
            set
            {
                startDate = value;
                if (EndDate == DateTime.MinValue)
                {
                    EndDate = value;
                }
            }
        }

        public virtual DateTime EndDate { get; set; }
        public virtual string Subject { get; set; }
        public virtual string Content { get; set; }
        public virtual string Memo { get; set; }
        public virtual int Order { get; set; }

        public virtual string TimeExpress()
        {
            var cStime1 = new ChinaCalendar(startDate);
            string cStime = cStime1.ChinaMonth + cStime1.ChinaDay;
            if (startDate == EndDate)
            {
                return StartDate.ToString("MM-dd") + " " + cStime;
            }
            var cEtime1 = new ChinaCalendar(EndDate);
            string cEtime = cEtime1.ChinaMonth + cEtime1.ChinaDay;
            return StartDate.ToString("MM-dd") + "至" +  EndDate.ToString("MM-dd") + " "+cStime + "至" +cEtime.ToString();
        }

        public override int GetHashCode()
        {
            return StartDate.GetHashCode() + EndDate.GetHashCode() + (Content + Memo).GetHashCode();
        }
    }
}